package Messages;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import ocsf.server.ConnectionToClient;
import server.SQLConnection;

public class MessageGetLendReport {

	private ConnectionToClient client ;
/**
 * constractor of this class 
 * @param client
 */
	public MessageGetLendReport(ConnectionToClient client) {
		super();
		this.client = client;
	}
/**
 * getting the lend report 	
 * @param str
 * @throws SQLException
 * @throws IOException
 */
public void getreport(String[] str) throws SQLException, IOException {
		
		try 
		{

			System.out.println("getting lend report");
			Statement stmt,stmt1;
			SQLConnection conn = new  SQLConnection();
			stmt = conn.getConnection().createStatement();
			stmt1 = conn.getConnection().createStatement();
			
					
					
			ResultSet rs1=stmt.executeQuery("SELECT * FROM db1.LendReportMonth ;");
			ArrayList<Object> arr=new ArrayList<Object>();
					
					
				try {
				
						if (rs1.next())
							{
							 arr.add("getlendreport");
							 rs1.previous();
							 while (rs1.next())
							 {
								 arr.add(rs1.getInt(1));
								 arr.add(rs1.getInt(2));
								 arr.add(rs1.getInt(3));
								 arr.add(rs1.getInt(4));
								 arr.add(rs1.getInt(5));
								 arr.add(rs1.getDate(6));
														
							 }
							client.sendToClient(arr);
								
									}
							else 
								{
								client.sendToClient("noreport");							
								}
  
					}
						catch (SQLException e)
								{	
								e.printStackTrace();
								}
		}
  
		catch (Exception ex )
		{
	  ex.printStackTrace();
		}
		
	}
}
